package fudan.se.project.repository.projection;

import fudan.se.project.domain.conference.Conference;
import fudan.se.project.domain.conference.Topic;
import fudan.se.project.domain.conference.role.Author;
import fudan.se.project.domain.conference.role.PcMember;
import fudan.se.project.repository.projection.summary.RoleSummary;
import fudan.se.project.repository.projection.summary.TopicSummary;

import java.util.*;


public class ConferenceProjection {


    private final Conference conference;


    private ConferenceProjection(Conference conference) {
        this.conference = conference;
    }

    public int getConferenceState() {
        return this.conference.getState().ordinal();
    }


    public int getConferenceStage() {
        return this.conference.getStage().ordinal();
    }


    public Set<TopicSummary> getTopics() {
        HashSet<TopicSummary> summaries = new HashSet<>();

        for (Topic topic : this.conference.getTopics()) {
            summaries.add(new TopicSummary(topic));
        }

        return summaries;
    }

    public RoleSummary getChair() {
        return new RoleSummary(this.conference.getChair());
    }

    public Set<RoleSummary> getPcMembers() {

        HashSet<RoleSummary> summaries = new HashSet<>();

        for (PcMember pcMember : this.conference.getPcMembers()) {
            summaries.add(new RoleSummary(pcMember));
        }
        return summaries;
    }

    public Set<RoleSummary> getAuthors() {

        HashSet<RoleSummary> summaries = new HashSet<>();

        for (Author author : this.conference.getAuthors()) {
            summaries.add(new RoleSummary(author));
        }
        return summaries;
    }

    public Long getId() {
        return this.conference.getId();
    }

    public String getShortname() {
        return this.conference.getShortname();
    }

    public String getFullname() {
        return this.conference.getFullname();
    }

    public String getPlace() {
        return this.conference.getPlace();
    }

    public Date getDateStart() {
        return this.conference.getDateStart();
    }

    public Date getDeadline() {
        return this.conference.getDeadline();
    }

    public Date getDateRelease() {
        return this.conference.getDateRelease();
    }

    public Date getDateEnd() {
        return this.conference.getDateEnd();
    }

    public Conference.ConferenceState getState() {
        return this.conference.getState();
    }

    public Conference.ConferenceStage getStage() {
        return this.conference.getStage();
    }

    public Conference.AllocationStrategy getStrategy() {
        return this.conference.getStrategy();
    }


    public static ConferenceProjection project(Conference conference) {
        return new ConferenceProjection(conference);
    }

    public static List<ConferenceProjection> project(Collection<Conference> conferences) {
        ArrayList<ConferenceProjection> arrayList = new ArrayList<>(conferences.size());
        for (Conference value : conferences) {
            arrayList.add(project(value));
        }
        return arrayList;
    }

}
